package com.woniu.userassembly.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.woniu.ly.model.model.*;

import com.woniu.userassembly.dao.*;
import com.woniu.userassembly.service.UserService;
import io.reactivex.rxjava3.core.Single;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private TravelerMapper travelerMapper;
    @Autowired
    private ComplaintsMapper complaintsMapper;
    @Autowired
    private CommentMapper commentMapper;
    @Override
    public User login(String userName) {
        return userMapper.login(userName);
    }

    @Override
    public void register(String userName, String userPassword,String userTel) {
       userMapper.register(userName,userPassword,userTel);
    }

    @Override
    public String quanxian(String userName) {
        return userMapper.quanxian(userName);
    }

    @Override
    public List<Product> selectProduct(String keyWord) {
        return userMapper.selectProduct(keyWord);
    }

    @Override
    public List<com.woniu.userassembly.model.UserOrder> selectOrder(int pageIndex, int pageNum,int userId) {
        return userMapper.selectOrder(pageIndex,pageNum,userId);
    }

    @Override
    public int orderCount(int userId) {
        return userMapper.orderCount(userId);
    }

    @Override
    public int makeOrder(com.woniu.userassembly.model.UserOrder userOrder) {
        userMapper.insert(userOrder);
        return userOrder.getUserOrderId();
    }

    @Override
    public void addTraveler(Traveler traveler) {
        travelerMapper.insert(traveler);
    }

    @Override
    public void makeComplaints(Complaints complaints) {
        complaintsMapper.insert(complaints);
    }

    @Override
    public void makeComment(Comment comment) {
        commentMapper.insert(comment);
    }

    @Override
    public void commentImg(CommentImg commentImg) {
        commentMapper.commentImg(commentImg);
    }

    @Override
    public void cancelOrder(int orderId) {
        userMapper.cancelOrder(orderId);
    }

    @Override
    public void makeOrderDetail(UserOrderDetail userOrderDetail) {
        userMapper.makeOrderDetail(userOrderDetail);
    }

    @Override
    public void cancelOrderDetail(int orderId) {
        userMapper.cancelOrderDetail(orderId);
    }

    @Override
    public double selectOrderPrice(int orderId) {
        return userMapper.selectOrderPrice(orderId);
    }

    @Override
    public void refundOrder(int orderId) {
        userMapper.refundOrder(orderId);
    }

    @Override
    public List<Integer> selectOrderIdd() {
        return userMapper.selectOrderIdd();
    }

    @Override
    public int travelerCount(int userId) {

        return travelerMapper.travelerCount(userId);
    }

    @Override
    public List<Traveler> selectTraveler(int userId, int i, int pageNum) {
        return travelerMapper.selectTraveler(userId,i,pageNum);
    }

    @Override
    public void pay(int orderId) {
        userMapper.pay(orderId);
    }

    @Override
    public void refundOrderPrice(com.woniu.userassembly.model.UserAccount userAccount) {
        userMapper.refundOrderPrice(userAccount);
    }

    @Override
    public int selectOrderUserId(int orderId) {
        return userMapper.selectOrderUserId(orderId);
    }

    @Override
    public void userAccount(com.woniu.userassembly.model.UserAccount userAccount) {
        userMapper.userAccount(userAccount);
    }

    @Override
    public int registerId() {
        return userMapper.registerId();
    }

    @Override
    public void insertUserRole(int userId) {
        userMapper.insertUserRole(userId);
    }

    @Override
    public double selectSeckillTourPrice(int seckillTourId) {
        return userMapper.selectSeckillTourPrice(seckillTourId);
    }

    @Autowired
    private UserOrderMapper userOrderMapper;

    @Override
    public com.woniu.ly.model.model.UserOrder findUserOrderById(int orderId) {
        return userOrderMapper.selectById(orderId);
    }

    @Autowired
    private TourMapper tourMapper;

    @Override
    public Tour selectTourById(int tourId) {
        return tourMapper.selectById(tourId);
    }

    @Override
    public void updateTourNowNum(Tour tour) {
        tourMapper.updateById(tour);
    }

    @Override
    public UserOrder selectOrderById(int orderId) {
        UserOrder userOrder = userOrderMapper.selectById(orderId);
        return userOrder;
    }

    @Override
    public List<Integer> selectTravelerIdByUserId(int userId) {
        return travelerMapper.selectTravelerByUserId(userId);
    }

    @Override
    public List<Tour> selectTourByTime(String timestamp) {
        return tourMapper.selectTourByTime(timestamp);
    }

    @Autowired
    private SeckillTourMapper seckillTourMapper;

    @Override
    public SeckillTour selectSeckillTourById(int tourId) {
        return seckillTourMapper.selectById(tourId);
    }

    @Override
    public void updateSeckillTourNowNum(SeckillTour seckillTour) {
        seckillTourMapper.updateById(seckillTour);
    }

    @Override
    public void updateUserOrder(UserOrder userOrder) {
        userOrderMapper.updateById(userOrder);
    }

    @Override
    public void changeOrderStatus(int orderId, String status) {
        userOrderMapper.changeOrderStatus(orderId,status);
    }

    @Autowired
    private CardMapper cardMapper;
    @Override
    public void addCard(Card card1) {
        cardMapper.insert(card1);
    }

    @Override
    public void platformAccount(double price,int id) {
        userMapper.platformAccount(price,id);
    }
    @Autowired
    private PlatformMapper platformMapper;
    @Override
    public void platformStatement(PlatfromStatement platfromStatement) {
        platformMapper.insert(platfromStatement);
    }

    @Override
    public double selectLastPlatformAccount() {
        return userMapper.selectLastPlatformAccount();
    }

    @Override
    public int findTraveler(int orderId) {
        return userMapper.findTraveler(orderId);
    }

    @Override
    public int travelNum(int tourId) {
        return userMapper.travelNum(tourId);
    }

    @Override
    public List<String> selectTel() {
        return userMapper.selectTel();
    }

    @Override
    public void insertCardId(int cardId, String travelerTel) {
        userMapper.insertCardId(cardId,travelerTel);
    }

    @Override
    public Card selectCard(String cardNum) {
        QueryWrapper<Card> cardQueryWrapper = new QueryWrapper<>();
        cardQueryWrapper.eq("card_num",cardNum);
        return cardMapper.selectOne(cardQueryWrapper);
    }

    @Override
    public int updateCard(Card idCard) {
        cardMapper.updateById(idCard);
       return  idCard.getCardId();
    }

    @Autowired
    private UserCardMapper userCardMapper;

    @Override
    public void update(int upCardId, int userId) {
        User user = userCardMapper.selectById(userId);
        user.setCardId(upCardId+"");
        userCardMapper.updateById(user);
    }

    @Override
    public void refundTraveler(int traId) {
        userMapper.refundTraveler(traId);
    }
}
